﻿using System;
using System.IO;


namespace Log
{
    public class FileLogger
    {
        readonly StreamWriter StreamWriter;
        readonly object LockForWriting = new object();

        public FileLogger(string fileName)
        {
            FileInfo fileInfo = new FileInfo($"{DateTime.Now:yyyy-MM-dd}.{fileName}.log");
            StreamWriter  = fileInfo.AppendText();
            StreamWriter.AutoFlush = true;
        }

        public void Write(string msg)
        {
            lock (LockForWriting)
            {
                StreamWriter.Write
                (
                    "\r\n\r\n"
                    + $"============={DateTime.Now:yyyy-MM-dd HH:mm:ss}===============\r\n"
                    + msg
                    + "\r\n\r\n"
                );
            }
        }

    }
}
